package logic

import (
	"context"
	"errors"
	"user_srv/models/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
	return &UserLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserLoginLogic) UserLogin(in *user.UserLoginRequest) (*user.UserLoginResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	err := u.UserInfo(in.Mobile)
	if err != nil {
		logx.Error("查询用户信息错误")
		return nil, errors.New("查询用户信息错误")
	}

	if u.Password != in.Password {
		logx.Error("密码不一致")
		return nil, errors.New("密码不一致")
	}
	//get := cache.Rdb.Get(l.ctx, "SendSmslogin"+in.Mobile)
	//if get.Val() != in.SendSms {
	//	logx.Error("获取短信验证码错误")
	//	return nil, errors.New("获取短信验证码错误")
	//}
	return &user.UserLoginResponse{
		UserId: int64(u.ID),
	}, nil
}
